// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import *as echarts from 'echarts'

//引入element-ui 组件
import ElementUI from 'element-ui'
//引入element-ui 的样式
import 'element-ui/lib/theme-chalk/index.css'
//全局加载element-ui 组件
Vue.use(ElementUI)

Vue.config.productionTip = false

Vue.prototype.$echarts = echarts
/* 定义一个导航钩子函数
to:到达的下一个路由对象
from:从那个路由来的路由对象
next:想当于java的放行函数
*/
router.beforeEach(function(to, from, next) {
  //取出登录用户名，判断是否登录过
  var userName = localStorage.getItem("userName");
  console.log("userName=" + userName)
  console.log(to)
  //判断路由地址里是否配置了meta的islogin
  if (to.meta.isLogin) {
    if (userName == null) {
      next("/loginEle");
    } else {
      //允许访问
      next()
    }

  } else {
    //放行
    next();
  }

})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
